import {defineStore} from "pinia";
import defaultSettings from "@/settings";
import {useDynamicTitle} from "@/utils/soul";
import {darkTheme} from "naive-ui";

// 布局设置
const {
    darkSideTheme,
    showSettings,
    themeColor,
    title,
    dynamicTitle
} = defaultSettings

const useSettingsStore = defineStore("settings", {

    state: () => ({
        title: title,
        themeColor: themeColor,
        darkSideTheme: darkSideTheme,
        showSettings: showSettings,
        dynamicTitle: dynamicTitle,
        collapsed: false,                           // 菜单收缩
    }),
    getters:{
        getTheme(){
            return this.darkSideTheme ? darkTheme : null
        }
    },
    actions:{
        setCollapsed(val) {
            this.collapsed = val
        },
        // 修改布局设置
        changeSetting(data){
            const {key , value} = data;
            // eslint-disable-next-line no-prototype-builtins
            if (this.hasOwnProperty(key)){
                this[key] = value;
            }
        },
        // 设置网页标题
        setTitle(title) {
            this.title = title;
            useDynamicTitle();
        },
    }
})

export default useSettingsStore;
